﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Blood : MonoBehaviour
{
    /// <summary> 移动速度 </summary>
    float moveSpeed = 8;

    [SerializeField] GameObject effect;

    /// <summary> 检测是否进入吸附范围 </summary>
    /// <param name="col">被碰撞体</param>
    void OnTriggerStay(Collider col)
    {
        if (col.gameObject.tag == "PlayerRange")
        {
            //经验球看向玩家
            gameObject.transform.LookAt(col.gameObject.transform.position);
            //经验球向前位移
            gameObject.transform.Translate(Vector3.forward * Time.deltaTime * moveSpeed, Space.Self);
        }
    }

    /// <summary> 检测血球是否被player碰到 </summary>
    /// <param name="col">被碰撞体</param>
    void OnTriggerEnter(Collider col)
    {
        if (col.gameObject.tag == "Enemy")
        {
            col.GetComponentInParent<Enemy>().PlusBlood();//调用player里的getEmpirical脚本
            Destroy(gameObject);
        }
        else if (col.gameObject.tag == "Player")
        {
            col.GetComponentInParent<Player>().PlusBlood();//调用player里的getEmpirical脚本

            GameObject eff = Instantiate(effect, col.gameObject.transform.position, col.gameObject.transform.rotation);
            eff.transform.SetParent(col.gameObject.transform.Find("model"));
            Destroy(gameObject);
        }
    }
}
